package com.salesystem.strust.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.salesystem.dao.entity.Customer;
import com.salesystem.dao.entity.Customertype;
import com.salesystem.dao.entity.Employee;
import com.salesystem.dao.interfaces.CustomerBiz;
import com.salesystem.util.Pagination;

@Controller
public class CustomerAction extends ActionSupport {
	@Resource
	CustomerBiz biz;	
	private Pagination paging;
	private List<Customer> customers;
	private List<Customer> list;
    private int pageNo = 1;
	private String parentID  ;
	private Customer customer;
	private Customertype customertype;
	private Employee employee;
	private String cid;
	
	
	public String getCid() {
		return cid;
	}
	public void setCid(String cid) {
		this.cid = cid;
	}
	public Employee getEmployee() {
		return employee;
	}
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public Customertype getCustomertype() {
		return customertype;
	}
	public void setCustomertype(Customertype customertype) {
		this.customertype = customertype;
	}
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	public List<Customer> getList() {
		return customers;
	}
	public void setList(List<Customer> customers) {
		this.customers = customers;
	}
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public String getParentID() {
		return parentID;
	}
	public void setParentID(String parentID) {
		this.parentID = parentID;
	}
	public Pagination getPaging() {
		return paging;
	}
	public void setPaging(Pagination paging) {
		this.paging = paging;
	}

	
	
	public String add(){
		return SUCCESS;
	}
	public String newCustomer(){
		return SUCCESS;
	}
	public String list(){
    	list = biz.getCusteomerList();
    	paging = new Pagination(pageNo, 15,list.size(), 5,"getCustomserList_action.action","pagenum");
    	customers = paging.getPageDate(list);
    	for(Customer c:list){
    		System.out.println(c.getEmployee().getName());
    	}
    	return "list";   
	}
	public String del(){
		biz.delCustomer(cid);
		return list();
	}
	public String update(){
		//biz.updateCustomer(cid);
		customer=biz.viewCustomer(cid);
		return "update";
	}
	public String updateCustomer(){
		
		biz.updateCustomer(cid,customer, customertype);	
		return list();
	}
	
	public String view(){
		customer=biz.viewCustomer(cid);
		return "view";
	}
	public String importCustomer(){
		return SUCCESS;
	}
	
	

}
